<template>
  <van-nav-bar
    :title="title"
    left-text="返回"
    left-arrow
    fixed
    safe-area-inset-top
    @click-left="goBack"
    class="nav-bar"
  >
    <template #title>
      <slot name="title">{{ title }}</slot>
    </template>
  </van-nav-bar>
</template>

<script setup>
import { useRouter } from 'vue-router';

const router = useRouter();
const props = defineProps({
  title: {
    type: String,
    default: '返回'
  }
});

const goBack = () => {
  if (window.history.state.back) {
    router.go(-1);
  } else {
    router.push('/');
  }
};
</script>

<style scoped>
.nav-bar {
  --van-nav-bar-height: 46px;
  --van-nav-bar-arrow-size: 18px;
  --van-nav-bar-text-color: #333;
  --van-nav-bar-title-text-color: #333;
}
</style>


